var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    waitList:[]
  },
  gowal(e) {
    wx.setStorageSync('istab', true)
    let orderId = e.currentTarget.dataset.id
    let waitStatus = e.currentTarget.dataset.status
    let waitItemRecordId = e.currentTarget.dataset.waitid
    if (waitStatus == 1) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=dispatch&&orderId=' + orderId,
        })
      }))

    } else if (waitStatus == 2) {
      if (app.globalData.identity == 5 || app.globalData.identity == 8) {
        this.readWaitItem(waitItemRecordId).then((res => {
          wx.navigateTo({
            url: '/pages/projectDetails/projectDetails?orderId=' + orderId,
          })
        }))


      } else if (app.globalData.identity == 4) {
        this.readWaitItem(waitItemRecordId).then((res => {
          wx.navigateTo({
            url: '/pages/projectDetails/projectDetails?orderId=' + orderId,
          })
        }))

   
      }
    } else if (waitStatus == 3) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=finished&&orderId=' + orderId,
        })
      }))

    } else if (waitStatus == 4) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=delivery' + '&&orderId=' + e.currentTarget.dataset.id,
        })
      }))

    } else if (waitStatus == 5) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=chenkacceptance' + '&&orderId=' + e.currentTarget.dataset.id,
        })
      }))
      // wx.navigateTo({
      //   url: '/shopowner/pages/Inneracceptance/Inneracceptance?todo=check' + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else if (waitStatus == 6) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=finished' + '&&orderId=' + e.currentTarget.dataset.id,
        })
      }))
      // wx.navigateTo({
      //   url: '/shopowner/pages/Inneracceptance/Inneracceptance?todo=check' + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else if (waitStatus == 7) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=maintain&&orderId=' + e.currentTarget.dataset.id,
        })
      }))

    } else if (waitStatus == 8) {
      this.readWaitItem(waitItemRecordId).then((res => {
       let todo = 'design'
        wx.navigateTo({
          url: '/shopowner/pages/previewOrder/previewOrder?todo=' + todo + '&&orderId=' +  e.currentTarget.dataset.id,
        })

      }))
      // wx.navigateTo({
      //   url: '/shopowner/pages/previewOrder/previewOrder?todo=design' + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else if (waitStatus == 9) {
      wx.navigateTo({
        url: '/pages/projectDetails/projectDetails?todo=finished&&orderId=' + e.currentTarget.dataset.id,
      })
    } else if (waitStatus == 10) {
      wx.navigateTo({
        url: '/pages/projectDetails/projectDetails?todo=delivery&&orderId=' + e.currentTarget.dataset.id,
      })
    }
  },

  // 86.读取待办事项
  readWaitItem(waitItemRecordId) {
    let t = this
    return new Promise((resolve, reject) => {
      wx.request({
        url: app.globalData.Interfaceurl + 'readWaitItem',
        method: "post",
        header: {
          "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
        },
        data: {
          waitItemRecordId: waitItemRecordId,

        },
        success: res => {
          wx.hideLoading()
          resolve("ok")

        },
        fail: err => {
          wx.showToast({
            title: '请求失败',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
        }
      })
    })
  },


  // 代办事项
  getWaitItem() {
    let t = this
    wx.showLoading({
      title: '加载中',
      
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getWaitItem',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
      },
      success: res => {
        console.log(res)
        wx.hideLoading()
        t.setData({
          waitList: res.data.waitItem
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getWaitItem()
    this.setData({
      identity:app.globalData.identity
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})